/*
 * @Description: 返回
 * @Author: kanglin
 * @Date: 2018-07-20 17:51:57
 * @Copyright: Created by Panxsoft.
 */

<style lang="less" scoped rel="stylesheet/less" type="text/less" >
    @pad-radio: 10rem / 1536;
    .back{
        // background: rebeccapurple;
        z-index: 9999999;
        position: fixed;
        left: 24* @pad-radio;
        top: 24* @pad-radio;
        width: 46 * @pad-radio ;
        height:46 * @pad-radio ;
        &>img{
            width: 100%;
        }
    }
    // .arrow{
    //     height:46 * @pad-radio ;
    //     width:46px;
    //     display: block;
    //     background-image: url('');
    //     background-repeat: no-repeat;
    //     background-position: center;
    //     background-size: 100%;
    // }
</style>

<template>
	<div
		class="back"
		@click="back">
		<img
			src="//gz.bcebos.com/v1/beauty-mirror/wx_system/lucky-money/back.png"
			alt="">
	</div>
</template>

<script>
export default {
	name: 'Back',
	props: {
		path: { // app or web
			type: String,
			default() {
				return '';
			},
		},
	},
	data() {
		return {
			is_pad: true,
		};
	},
	created() {
		this.revolveScreenType();
	},
	methods: {

		/**
		 * 判断屏幕宽
		 * @return {undefined} {description}
		 */
		revolveScreenType() {
			this.is_pad = document.body.clientWidth > 460;
		},
		/**
         *  通知app 返回
		 * 	@return {undefined}
         */
		back() {
			if (this.path === '') {
				this.backToApp();
			} else {
				this.$router.replace({
					path: this.path,
				});
			}
		},

		/**
		 *  返回到app
		 */
		backToApp() {
			try { // for iOS
				window.webkit.messageHandlers.getBack.postMessage('getBack');
			} catch (e) { //
				console.error(e.messsage);
			}

			try {
				/* global XJXX */ // for Android
				XJXX.back();
			} catch (e) {
				console.error(e.messsage);
			}

			if (this.inDevice('Windows')) {
				alert('返回首页');
			}
		},

		inDevice(needle) {
			return navigator.userAgent.indexOf(needle) !== -1;
		},
	},
};
</script>

<style scoped>

</style>
